home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / ascutils.zip / FLAGS.ASM < prev    next >
Assembly Source File  |  1988-05-25  |  7KB  |  273 lines

  1. ;
  2. ;                  FLAGS
  3. ;
  4.  
  5. codeseg        segment
  6.         assume    cs:codeseg, ds:codeseg
  7.  
  8.  
  9.         org    100h
  10.  
  11. flags        proc    far
  12.  
  13. start:        jmp    Main_1
  14.  
  15. XT_FCB:                    ; search (extended) FCB
  16.         db    0FFh        ; flag byte for    extended FCB
  17.         db    0, 0, 0, 0, 0    ; reserved bytes
  18. search_attr    db    27h        ; search attribute byte
  19. drive_no    db    0        ; drive    number (0 = default)
  20.         db    8 dup(0)    ; filename
  21.         db    3 dup(0)    ; file extension
  22.         db    25 dup (0)    ; various info (we won't need)
  23.  
  24. DTA_FCB:                ; DTA, to receive new FCB from
  25.         db    0FFh        ;  Find    First and Find Next
  26.         db    0, 0, 0, 0, 0
  27. f_attr        db    0
  28. f_drive        db    0
  29. f_name        db    8 dup(0)
  30. f_ext        db    3 dup(0)
  31.         db    25 dup (0)
  32.  
  33. file_count    dw    0
  34. msg_1        db    0Dh, 0Ah, 'FLAGS: File not found$', 0Dh, 0Ah
  35. msg_2        db    0Dh, 0Ah, 'Unable to change flags on file $', 0Dh, 0Ah
  36. msg_3        db    0Dh, 0Ah, 'Invalid flag    value given$', 0Dh, 0Ah
  37.         db    8 dup (0)
  38. flag_chars    db    'R', 1,    'A', 020h, 'S',    4, 'H',    2, 0, 0, 0, 0, 0, 0
  39.     ; (alternate with attribute    bytes)    (0 is used as a    marker here)
  40.  
  41. pathname:                ; ASCIIZ pathname for attr change
  42. drv        db    0        ;  goes    here.
  43.         db    ':'
  44. file_name    db    13 dup (0)
  45.  
  46. curr_drive    db    0
  47. new_attr    dw    0
  48.  
  49.  
  50. Main_1:
  51.         mov    ah,19h        ; get logged drive into    al
  52.         int    21h
  53.         inc    al        ; incr (necessary)
  54.         mov    curr_drive,al    ; and save it.
  55.         call    get_flags    ; gets flags from command line
  56.         jc    Main_2        ; error    return
  57.         call    change_attr    ; principle function - gets file names
  58.                     ; using    find first/next    FCB, then
  59.                     ; changes (or resets) the attributes.
  60.  
  61. Main_2:
  62.         cmp    file_count,0    ; no files found ?
  63.         jne    Exit
  64.         mov    dx,offset msg_1
  65.         mov    ah,9
  66.         int    21h
  67.  
  68. Exit:
  69.         int    20h
  70.  
  71. flags        endp
  72.  
  73.  
  74. ;        SUBROUTINE
  75. ;        get flags from command line
  76.  
  77. get_flags    proc    near
  78.         mov    si,082h        ; point    si at 1st arg char
  79.         mov    cl,[si-2]    ; load cl with char count
  80.         xor    ch,ch
  81.  
  82. flagloop1a:
  83.         cmp    byte ptr [si],20h    ; look for first non-
  84.         jne    flagloop1b        ; space, if not
  85.         inc    si            ; already found
  86.         loop    flagloop1a
  87.         jmp    short flags_OK_ret    ; no flags ? OK.
  88.  
  89. flagloop1b:
  90.         cmp    byte ptr [si],0Dh    ; check    for eoln
  91.         je    short flags_OK_ret    ; no flags is ok.
  92.         cmp    byte ptr [si],20h
  93.         je    flagloop2
  94.         inc    si        ; continue - this skips    over the
  95.         loop    flagloop1b    ; required file    name argument
  96.                     ; (if it was given).
  97.         jmp    short flags_OK_ret    ; no flags
  98.  
  99. flagloop2:
  100.         inc    si            ; continue to input chars
  101.         cmp    byte ptr [si],20h    ; now we skip over spaces
  102.         jne    flags2
  103.         loop    flagloop2
  104.         jmp    short flags_OK_ret    ; no more flags
  105. flags2:
  106.         cmp    byte ptr [si],0Dh
  107.         je    flags_OK_ret        ; no more flags
  108.  
  109. flagloop3:
  110.         mov    di,offset flag_chars    ; table    of flag    chars
  111.         mov    al,[si]            ; si should point to one
  112.         call    upcase
  113. flagsck:
  114.         cmp    al,[di]            ; check    first flag
  115.         je    flagfound
  116.         cmp    byte ptr [di],0        ; marker for end of flag list
  117.         je    flags_bad_ret        ; invalid flag - error return
  118.         inc    di
  119.         inc    di            ; skip over attr byte
  120.         jmp    flagsck            ; continue
  121. flagfound:
  122.         inc    di            ; flag match found
  123.         mov    al,[di]            ; incr di to attr byte
  124.         or    byte ptr new_attr,al    ; save attr by 'or'ing
  125. flagloop3a:
  126.         inc    si            ; move si to next input    char
  127.         cmp    byte ptr [si],0Dh    ; check    for eoln
  128.         je    flags_OK_ret        ; exit with clc    if found
  129.         cmp    byte ptr [si],020h
  130.         jne    nextflag
  131.         loop    flagloop3a        ; loop over spaces
  132.         jmp    short flags_OK_ret    ; no more flags
  133. nextflag:
  134.         loop    flagloop3        ; continue getting chars
  135.  
  136. flags_OK_ret:
  137.         clc
  138.         ret
  139. flags_bad_ret:
  140.         mov    dx,offset msg_3        ; invalid flag message
  141.         mov    ah,9
  142.         int    21h
  143.         stc                ; error    return
  144.         ret
  145.  
  146. get_flags    endp
  147.  
  148.  
  149. ;
  150. ;        SUBROUTINE
  151. ;        Find first and find next using FCB, then change    attributes
  152.  
  153. change_attr    proc    near
  154.         mov    si,5Ch        ; drive    # and file name    in PSP
  155.         mov    di,offset drive_no    ; file name offset in search FCB
  156.         mov    cx,25h        ; char count (up to 81h)
  157.         cld
  158.         rep    movsb        ; xfer drive # and file    name
  159.         mov    dx,offset DTA_FCB    ; disk transfer    address
  160.         mov    ah,1Ah        ;  set here
  161.         int    21h
  162.  
  163.         mov    ah,11h        ; Find First using FCB
  164. find:
  165.         mov    dx,offset XT_FCB    ; point    ds:dx to search    FCB
  166.         int    21h
  167.         or    al,al        ; test al for 0    (success)
  168.         jz    chg1
  169.         ret            ; return from here when    no more    files
  170. chg1:
  171.         call    xfer_pathname    ; xfer file name from the FCB created
  172.                     ; by Find First    or Find    Next.
  173.         mov    dx,offset pathname     ; ASCIIZ pathname offset
  174.         mov    ah,43h        ; get/set file attribute
  175.         mov    al,1        ; al = 1 means 'set'
  176.         mov    cx,new_attr    ; new attribute
  177.         int    21h        ; doit
  178.  
  179.         jnc    chg2        ; success, jump    over error rtn
  180.         call    flags_err
  181. chg2:
  182.         inc    file_count    ; increment file count here
  183.         mov    ah,12h        ; Find Next using FCB
  184.         jmp    find        ;  continue ...
  185.  
  186. change_attr    endp
  187.  
  188.  
  189. ;        SUBROUTINE
  190. ;        transfer pathname to ASCIIZ holding area
  191.  
  192. xfer_pathname    proc    near
  193.         mov    si,offset f_name     ; file    name from search
  194.         mov    di,offset file_name     ; ASCIIZ holding area
  195.         mov    cx,8        ; filename char    count
  196.  
  197. xferloop_1:
  198.         lodsb            ; load first char into al
  199.         cmp    al,20h        ; space    here means end of name
  200.         je    xfer1        ; so jump, or
  201.         stosb            ; save the char    at es:di
  202.         loop    xferloop_1    ; continue
  203.  
  204. xfer1:
  205.         mov    al,2Eh        ; '.' char
  206.         stosb            ; insert at holding area
  207.         mov    cx,3        ; char count for extension
  208.         mov    si,offset f_ext        ; offset for ext
  209.  
  210. xferloop_2:
  211.         lodsb            ; get char into    al
  212.         cmp    al,20h        ; if space, done
  213.         je    xfer2
  214.         stosb            ; else save it
  215.         loop    xferloop_2    ; and continue...
  216.  
  217. xfer2:
  218.         xor    al,al        ; 0 al
  219.         stosb            ; place    'null' terminator at the
  220.                     ; end of the file name
  221.         mov    si,offset f_drive    ; drive    designation in created
  222.                         ; FCB
  223.         mov    al,[si]        ; place    in al and compare it with 0
  224.         cmp    al,0        ;  (0 indicates    'default drive')
  225.         jne    xfer3        ; if not 'default', skip next
  226.         mov    al,curr_drive    ; get current drive (saved before)
  227. xfer3:
  228.         add    al,40h        ; otherwise, add 040h to make ASCII
  229.         mov    drv,al        ; place    drive letter at    start of name
  230.         ret            ; and return.
  231. xfer_pathname    endp
  232.  
  233.  
  234. ;        SUBROUTINE
  235. ;        flags_err
  236.  
  237. flags_err    proc    near
  238.         mov    dx,offset msg_2        ; flags    error msg
  239.         mov    ah,9            ; output
  240.         int    21h
  241.         mov    si,offset pathname    ; pathname (set    up in
  242.                         ;  xfer_pathname routine)
  243. pname_loop:    lodsb            ; [si] into al
  244.         or    al,al        ; check    for 0 (null terminator)
  245.         jz    flags_err_ret    ; - if found, return
  246.         mov    ah,2        ; output file name char    by char
  247.         mov    dl,al
  248.         int    21h
  249.         jmp    pname_loop
  250. flags_err_ret:    ret
  251. flags_err    endp
  252.  
  253.  
  254. ;        SUBROUTINE
  255. ;        upper case
  256.  
  257. upcase        proc    near
  258.         cmp    al,61h        ; is char < 'a'    ?
  259.         jb    upcase_ret
  260.         cmp    al,7Ah        ; is char > 'z'    ?
  261.         ja    upcase_ret
  262.         sub    al,20h        ; no, it's a lower case    char,
  263.                     ;  so fix it.
  264. upcase_ret:
  265. last_line:                    ; (last    line of    pgm)
  266.         ret
  267. upcase        endp
  268.  
  269.  
  270. codeseg        ends
  271.  
  272.         end    start
  273.